﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Utils;
using Settings;
namespace PanasonicWarranty.DAL
{
    public partial class DBpa_Warranty
    {
        //// Since this class provides only static methods, make the default constructor private to prevent
        //// instances from being created with "new DBpa_Warranty()"
        private DBpa_Warranty() { }
        
        public static bool Create(string AgencyCode, string CustomerPhone, string ModelCode, string ProductCode, DateTime? RegisterDate)
		{
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, "sp_pa_Warranty_Insert", AgencyCode, CustomerPhone, ModelCode, ProductCode, RegisterDate);
                    return (result > 0);
                }
            }catch(Exception ex){
                throw ex;
            }
		}

		public static bool Update(int WarrantyID, string AgencyCode, string CustomerPhone, string ModelCode, string ProductCode, DateTime? RegisterDate)
		{
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, "sp_pa_Warranty_Update", WarrantyID, AgencyCode, CustomerPhone, ModelCode, ProductCode, RegisterDate);
                    return (result > 0);
                }
            }catch(Exception ex){
                throw ex;
            }
		}

		public static bool Delete(int WarrantyID)
		{
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, "sp_pa_Warranty_Delete", WarrantyID);
                    return (result > 0);
                }
            }catch(Exception ex){
                throw ex;
            }
		}

        public static SqlDataReader GetAll()
        {
            try
            {
                return SqlHelper.ExecuteReader(CommonSetting.ConnectionString, CommandType.StoredProcedure,"sp_pa_Warranty_GetByAll");
            }catch(Exception ex){
                throw ex;
            }
        }

        public static SqlDataReader GetByKey(int WarrantyID)
        {
            try
            {
                return SqlHelper.ExecuteReader(CommonSetting.ConnectionString, "sp_pa_Warranty_GetById", WarrantyID);
            }catch(Exception ex){
                throw ex;
            }
        }

        public static SqlDataReader GetByTop(string top, string where, string order)
        {
            try
            {
                return SqlHelper.ExecuteReader(CommonSetting.ConnectionString, "sp_pa_Warranty_GetByTop", top, where, order);
            }catch(Exception ex){
                throw ex;
            }
        }
	}
}
